package List;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/28
 * /**
 *  * @Description TODO
 *  * @Author chenmin
 *  *
 *  * List作业
 *  * 1.模拟登陆，编写用户类，测试类。
 *  *   1>.给集合中存储5个用户对象。
 *  *   2>.从控制台输入用户名和密码，和集合中的对象信息进行比较，相同表示成功，不同表示失败。
 *  *   3>.有三次输入机会。
 *  */

public class UserTest {
    public static void main(String[] args) {
        User user1 = new User("aaa","111");
        User user2 = new User("bbb","222");
        User user3 = new User("ccc","333");
        User user4 = new User("ddd","444");
        User user5 = new User("eee","555");
        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);
        list.add(user5);
        Scanner sc = new Scanner(System.in);
        int count=3;
        boolean flag=false;
        while(count>0){
            String name = JOptionPane.showInputDialog(null, "请输入账户：");
            System.out.println("s=" + name);
            String password= JOptionPane.showInputDialog(null, "请输入密码：");
            System.out.println("s=" + password);
            for(int i=0;i<list.size();i++){
                User u=list.get(i);
                if(u.getPassword().equals(password)&&u.getUserName().equals(name)){
                    JOptionPane.showMessageDialog(null, "登录成功"
                            , "通知", JOptionPane.INFORMATION_MESSAGE);
                    flag=true;
                    count=0;
                    break;
                }
                }
            if(flag){
                break;
            }
            count--;
            if(count==0){
                JOptionPane.showMessageDialog(null, "您的登录次数已用完！",
                        "警告", JOptionPane.WARNING_MESSAGE);
                break;
            }else{
                JOptionPane.showMessageDialog(null, "用户名或密码错误,请重新登录！",
                        "错误", JOptionPane.ERROR_MESSAGE );
            }
        }
    }
}
